package org.jeecg.modules.api.xxApi.validate;

import org.apache.commons.lang3.ArrayUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 枚举校验注解处理类
 */
public class EnumValueValidator implements ConstraintValidator<EnumValue, Object> {

    private String[] values;

    @Override
    public void initialize(EnumValue constraintAnnotation) {
        values = constraintAnnotation.values();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        if(value == null){
            //为空不校验
            return true;
        }
        if(ArrayUtils.contains(values,value.toString())){
            return true;
        }
        return false;
    }
}